package com.wc.alorithm_blue_bridge._二分.A_Careful_Approach;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/4/11 11:42
 * @description
 * https://www.lanqiao.cn/problems/1390/learning/?page=1&first_category_id=1&tag_relation=union&name=A%20C
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 10;
    static boolean[] st = new boolean[N];
    static int[][] a = new int[N][2];
    static int n;

    public static void main(String[] args) {
        int t = 1;
        while ((n = sc.nextInt()) != 0) {
            for (int i = 1; i <= n; i++) {
                a[i][0] = sc.nextInt() * 60 * 100;
                a[i][1] = sc.nextInt() * 60 * 100;
            }
            int l = 0, r = 1440 * 60 * 100;
            while (l < r) {
                int mid = (l + r + 1) / 2;
                Arrays.fill(st, 1, n + 1, false);
                if (check(mid, 0)) l = mid;
                else r = mid - 1;
            }
            int ans = Integer.parseInt(String.format("%.0f", l / 100.0));
            out.printf("Case %d: %d:%02d\n", t, ans / 60, ans % 60);
            t ++;
        }
        out.flush();
    }

     static boolean check(int mid, int t) {
         for (int i = 1; i <= n; i++) {
             if (!st[i]) {
                 if (t > a[i][1]) continue;
                 st[i] = true;
                 if (t < a[i][0]) {
                     if (check(mid, a[i][0] + mid)) return true;
                 } else if (check(mid, t + mid)) return true;


                 st[i] = false;
             }
         }
         for (int i = 1; i <= n; i++) {
             if (!st[i]) return false;
         }
         return true;
     }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}